<%--
  Created by IntelliJ IDEA.
  User: 任旭旺
  Date: 2020/6/1
  Time: 11:16
  To change this template use File | Settings | File Templates.
--%>
<%--
  Created by IntelliJ IDEA.
  User: zyvictor
  Date: 2020/5/31
  Time: 22:15
  To change this template use File | Settings | File Templates.
--%>

<%@ page contentType="text/html;charset=UTF-8" pageEncoding="utf-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page isELIgnored="false" %>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
    <c:set var="request" value="${pageContext.request.contextPath}"/>
    <title></title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="${request}/static/plugins/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="${request}/static/plugins/layuiadmin/style/admin.css" media="all">
</head>
<body>

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <div class="layui-form-item">

            </div>
        </div>
        <div class="layui-card-body">
            <table id="auditList" lay-filter="LAY-app-content-comm"></table>
            <script type="text/html" id="table-content-list1">
                <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i
                        class="layui-icon layui-icon-edit"></i>审核</a>
            </script>
        </div>
    </div>
</div>

<script src="${request}/static/plugins/layuiadmin/layui/layui.js" charset="UTF-8"></script>
<script>
    layui.config({
        base: '${request}/static/plugins/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'contlist', 'table', 'laypage'], function () {
        var $ = layui.$
            , admin = layui.admin
            , form = layui.form
            , table = layui.table
            , laypage = layui.laypage;

        //方法级渲染
        table.render({
            elem: '#auditList'
            , url: '${request}/vacation/auditVacationList.html' //向后端默认传page和limit
            , cols: [[
                {type: 'numbers', fixed: 'left'}
                , {field: 'vacationReqId',title:'假期编号'}
                , {field: 'empId', title:'编号'}
                , {field: 'name', title: '请假人'}
                , {field: 'vacationStr', title:'请假时间'}
                , {field: 'submitTime', title: '提交时间'}
                , {title: '操作', minWidth: 150, align: 'center', fixed: 'right', toolbar: '#table-content-list1'}
            ]]
            , page: true
            , limit: 10
            , limits: [5, 10, 15, 20]
            , id: 'auditList'
            , request: {
                pageName: 'pageNum',
                limitName: 'pageSize'  //如不配置，默认为page=1&limit=10
            }
            , done: function (res, curr, count) {
                //如果是异步请求数据方式，res即为你接口返回的信息。
                //如果是直接赋值的方式，res即为：{data: [], count: 99} data为当前页数据、count为数据总长度
                console.log(res);

                //得到当前页码
                console.log(curr);

                //得到数据总量
                console.log(count);
            }

        });


        //监听工具条
        table.on('tool(LAY-app-content-comm)', function (obj) {
            var data = obj.data;

            if (obj.event === 'edit') {
                layer.open({
                    type: 2
                    ,
                    title: '审核假期'
                    ,
                    content: '${request}/vacation/auditVacationForm.html'
                    ,
                    maxmin: true
                    ,
                    area: ['820px', '730px']
                    ,
                    btn: ['确定', '取消']
                    ,
                    yes: function (index, layero) {
                        var iframeWindow = window['layui-layer-iframe' + index]
                            , submit = layero.find('iframe').contents().find("#layuiadmin-app-form-edit");

                        //监听提交
                        iframeWindow.layui.form.on('submit(layuiadmin-app-form-edit)', function (data) {
                            var field = data.field; //获取提交的字段
                            console.log(field);
                            var json = {
                                vacationReqId: field.vacationId
                                , empId: field.id
                                , reqStatus:field.status
                            };

                            $.ajax({
                                data: json,
                                type: 'post',
                                url: "${request}/vacation/modifyEmpVacation.html",
                                success: function (data) {
                                    if (data.code == 100) {
                                        layer.msg('审批成功', {
                                            icon: 1
                                            , time: 1000
                                        });

                                        obj.del(json); //数据更新


                                        form.render();

                                        layer.close(index); //关闭弹层
                                    } else {
                                        return layer.msg('未知错误');
                                    }
                                }
                            });

                        });

                        submit.trigger('click');
                    }
                    ,
                    success: function (layero, index) {
                        //给iframe元素赋值
                        var othis = layero.find('iframe').contents().find("#layuiadmin-app-form-list").click();
                        othis.find('input[id="vacationId"]').val(data.vacationReqId);
                        othis.find('input[id="id"]').val(data.empId);
                        othis.find('input[name="name"]').val(data.name);
                        othis.find('input[name="vacationStr"]').val(data.vacationStr);
                        othis.find('textarea[id="reason"]').val(data.reason);
                        console.log(data.reason);
                    }
                });
            }
        });

    });
</script>
</body>
</html>

